var addPage = avalon.define({
	$id: "page",
	uid: "",
	integralNum: 0,
	receiptedPageNo: 1,
	receipted: [],
	noReceiptedData: "",
	receiptedTotal: 0
});

mui.ready(function() {
	var uid = $("#uid").val();
	addPage.uid = uid;
	var _a = $.getUrlParam("a");
	if(!_a) {
	var url = "dahua://header?title="+$.i18n.prop("Bonus_Point_List");
		mui.openWindow({
			url: url 
		});
	}
	if("" != uid) {
		mui.ajax('/user/get.json', {
			data: {
				uid: addPage.uid
			},
			dataType: 'json',
			success: function(data) {
				if(""!=data&&null!=data){
					addPage.integralNum=data.customer.integral;
				}
			}
		});
	}
	
	mui('#form').on('tap','li',function(){
		var url=$(this).attr('data-url');
		mui.openWindow({
			url: url
		});
	});
	mui.init({
		pullRefresh:{
			container:'#pullrefresh',
			down:{
				style:'circle',
				contentdown: $.i18n.prop('contentDown'),
				contentover: $.i18n.prop('contentOver'),
				contentrefresh: $.i18n.prop('contentRefresh'),
				contentnomore: $.i18n.prop('noData'),
				callback:pulldownRefresh
			},
			up:{
				auto:true,
				contentdown: $.i18n.prop('contentDown'),
				contentover: $.i18n.prop('contentOver'),
				contentrefresh: $.i18n.prop('contentRefresh'),
				contentnomore: $.i18n.prop('noData'),
				callback: pullupRefresh
			}
		}
	});
	// 上拉加载
	function pulldownRefresh(){
		var self = this;
		addPage.receiptedPageNo = 1;
		addPage.receipted = [];
		addPage.noReceiptedData = "";
		mui.ajax('/integral/logging/list.json', {
			data: {
				'customer.id': addPage.uid,
				
			},
			dataType: 'json',
			type:'post',
			success: function(data) {
				console.log(data);
				var records = data.records;
				addPage.receiptedTotal = data.totalCount;
				if(null == records || records.length == 0) {
					addPage.receipted = [];
					addPage.noReceiptedData = "<img src='../../resources/images/noDataImg.png'><p>"+$.i18n.prop('No_data')+"</p>";
				} else {
					addPage.receipted = records;
					addPage.noReceiptedData = "";
					addPage.receiptedPageNo = 2;
				}
				i18nReady();
				self.endPulldownToRefresh(false);
			}
		});
	}
	// 下拉刷新
	function pullupRefresh(){
		// mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);//参数为true代表没有更多数据了.
		var self = this;
		addPage.noReceiptedData = "";
		
		mui.ajax('/integral/logging/list.json', {
			data: {
				'customer.id': addPage.uid,
				"pageNo": addPage.receiptedPageNo,
			},
			dataType: 'json',
			type:'post',
			success: function(data) {
				console.log(data);
				var records = data.records;
				addPage.receiptedTotal = data.totalCount;
				if((addPage.receiptedPageNo <= data.totalPage) && (null != records)) {
					addPage.receipted = addPage.receipted.concat(records);
					addPage.receiptedPageNo++;
				} else {
					mui.toast($.i18n.prop('noData'));
				}
				if(data.totalCount == 0) {
					addPage.noReceiptedData = "<img src='../../resources/images/noDataImg.png'><p>"+$.i18n.prop('No_data')+"</p>";
				} else {
					addPage.noReceiptedData = "";
				}
				i18nReady();
				self.endPullupToRefresh(false);//参数为true代表没有更多数据了.
			}
		});
	}
});
